import requests
from lxml import etree
import urllib.request


def img_list():
    url = "https://www.duitang.com/album/?id=78640794"
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36 Edg/96.0.1054.43"
    }
    response = requests.get(url=url, headers=headers)
    response.encoding = "utf-8"
    tree = etree.HTML(response.text)
    img_list = tree.xpath("//div[@class='woo-swb']//div[@class='mbpho']/a/img")

    for i in img_list:
        name = i.xpath("./@alt")[0]
        filename = "./img_12/" + name + ".jpeg"
        src = i.xpath("./@src")[0]
        src2 = src
        # print(filename,src2)
        urllib.request.urlretrieve(url=src2, filename=filename)
        print(name + "----" + src2)


if __name__ == '__main__':
    img_list()
